package com.jeeplus.modules.tools.utils;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * 服务端的参数工具类
 */
public class HttpRequestUtils
{
    /**
     * 获取当前客户端请求传入的参数
     * @param request
     * @return
     */
    public static HashMap getRequestParams(HttpServletRequest request)
    {
        //从HttpServletRequest request中获取前台传来的所有参数值：
        String requestParas = "";
        Map map11 = request.getParameterMap();
        Set keSet = map11.entrySet();

        HashMap paramMap = new HashMap<>();
        for(Iterator itr = keSet.iterator(); itr.hasNext();)
        {
            Map.Entry me=(Map.Entry)itr.next();
            Object key=me.getKey();
            Object valueStr=me.getValue();
            String[] value=new String[1];
            if(valueStr instanceof String[]){
                value=(String[])valueStr;
            }else{
                value[0]=valueStr.toString();
            }
            for(int k=0;k<value.length;k++)
            {
                requestParas+="\nparamKey="+key+",paramValue="+value[k];
                paramMap.put(key, value[k]);
            }
        }
//        System.out.println("listData listData 接收前台的参数="+requestParas);
        return paramMap;
    }
}
